<template>
	<div>
		<el-form ref="form" :model="form" label-width="100px">

			<el-form-item label="客户姓名" prop="userName">
				
				<el-select v-model="form.userName" placeholder="请选择客户" clearable :style="{width: '100%'}" @change="change()">
					<el-option v-for="(item, index) in userData" :key="index" :label="item.userName" :value="item.userName"
						:disabled="item.disabled"></el-option>
				</el-select>
				
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex" placeholder="请选择客户" clearable :style="{width: '100%'}" @change="change()">
					<el-option v-for="(item, index) in sexData" :key="index" :label="item.label" :value="item.value"
						:disabled="item.disabled"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="退住类型" prop="exitType">
				<el-select v-model="form.exitType" placeholder="请选择退住状态" clearable :style="{width: '100%'}">
					<el-option v-for="(item, index) in stayBackData" :key="index" :label="item.label" :value="item.value"
						:disabled="item.disabled"></el-option>
				</el-select>
				
			</el-form-item>
			<el-form-item label="退住原因" prop="exitCause">
				<el-input v-model="form.exitCause"></el-input>
			</el-form-item>
			<el-form-item label="退住时间" prop="endTime">
				<el-date-picker v-model="form.endTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}"
				 placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="备注" prop="note">
				<el-input v-model="form.note"></el-input>
			</el-form-item>
			<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'ExitRegistrationEdit',
		components: {

		},
		props: [
			'showEdit',
			'exitId',
			'editid'
		],
		data() {
			return {
				form: {
				},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				stayBackData: [{
					"label": "正常退住",
					"value": "正常退住"
				}, {
					"label": "保留床位",
					"value": "保留床位"
				},{
					"label": "死亡退住",
					"value": "死亡退住"
				}],
				// isupdate: false,
				url: '/exitRegistration/save',
				registerlevel: [],
				depts: [],
				userData:[],
			}
		},
		created() {
			// this.init()
			// console.log("this.editid:" + this.editid)
			if (this.editid) {
				this.url='/exitRegistration/save'
				this.axios.get('/exitRegistration/toedit', response => {
					this.form=response.obj
				}, {
					id: this.editid
				})
			}
			
			this.axios.get('/user/findUser', res => {
				this.userData=res.obj
			})
			
		},
		methods: {
			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			},
			change(){
				for(let i=0;i<this.userData.length;i++){
					if(this.userData[i].userName==this.form.userName){
						this.form.sex=this.userData[i].sex;
						this.form.age=this.userData[i].age;
						this.form.fileNum=this.userData[i].fileNum;
						this.form.startTime=this.userData[i].startTime;
						break;
					}
				}
			}

		}
	}
</script>

<style>
</style>
